package com.dayuanit.dy11.mall.mallspringboot.controller;

import com.dayuanit.dy11.mall.mallspringboot.entity.CommodityWithBLOBs;
import com.dayuanit.dy11.mall.mallspringboot.service.CommoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;

@Controller
public class PageController {

    @Autowired
    private CommoService commoService;

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String toIndex() {
        return "home/home";
    }

    @RequestMapping(value = "/toCommonDetail", method = RequestMethod.GET)
    public String toCommonDetail(int commoId, HttpServletRequest request) {
        //TODO 加载商品信息
        final CommodityWithBLOBs commodityWithBLOBs = commoService.loadCommo(commoId);
        request.setAttribute("commoDetail", commodityWithBLOBs);
        return "home/introduction";
    }

    @RequestMapping(value = "/toCommonDetail2/{commoId}", method = RequestMethod.GET)
    public String toCommonDetail2(@PathVariable("commoId") int commoId, HttpServletRequest request) {
        //TODO 加载商品信息
        final CommodityWithBLOBs commodityWithBLOBs = commoService.loadCommo(commoId);
        request.setAttribute("commoDetail", commodityWithBLOBs);
        return "home/introduction";
    }

    @RequestMapping(value = "/toCart", method = RequestMethod.GET)
    public String toCart() {
        return "home/shopcart";
    }
}
